﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufBase.h"
#include "GnufComponent.h"
#include "GnufItemEvents.h"
#include "GnufINotificationCenterEventHandler.h"

namespace gnuf {
    class Info;
    class TabBar;
    class Tab;
    class GraphicsCanvas;
    class DisplayManagerEventArgs;
    class ProjectDisplayEventArgs;
    class AssetDisplayEventArgs;
    class IAssetDisplay;
    class FamilyTypeButton;
    class IProjectDisplay;
    class Scenario;
    class TiledShowcaseMaintainer;
    class IsolatedArrangementAreaContent;
    class QtHightlight;

    namespace impl { class ViewTabBarImpl; }

    class GNUF_BASE_EXPORT ViewTabBar final
        : public Component
        , public IItemEventHandler
        , public INotificationCenterEventHandler
    {
        DEFINE_CAST_DERIVED(ViewTabBar, Component)
        GNUF_IMPL_USE(ViewTabBar)
    public:
        explicit ViewTabBar(const std::wstring & key, bool major);
        virtual ~ViewTabBar();
        static ViewTabBar * get();
        bool isMajor() const;
        bool isMinor() const { return !isMajor(); }
        GraphicsCanvas * relatedGraphicsCanvas();
        enum class EReasonOfTransferring { eOnIsolating, eOffIsolating, eOnTiling, eOffTiling };
        void transferOneTo(ViewTabBar *, const IAssetDisplay * const, const ViewTabBar::EReasonOfTransferring);
        void transferAllTo(ViewTabBar *, const ViewTabBar::EReasonOfTransferring);

        void switchToNextTab();

        ///\return Return true, if it's in the showcase (isolated or/and tiled). Otherwise, return false.
        bool  hasShowcase() const;
        ///\brief Quit the showcase (isolated or/and tiled).
        void quitShowcase();

        const Tab * tabById(const std::string &) const;
    protected:
        // Inherits from Component...
        virtual void initialize(Toolbar *) override;
        virtual gcmp::OwnerPtr<QtToolbar> createQtToolBar(Toolbar*) override;
        virtual void onEvent(ArrangementAreaEvent *) override;
        virtual gcmp::OwnerPtr<ArrangementAreaContent> 
            clone() const override;
        virtual void onPostConnectedWithArrangementArea() override;
        virtual void onPreDisconnectedFromArrangementArea() override;

        // Inherits from IItemEventHandler...
        virtual void onCurrentIndexChanged(TabBar *) override;
        virtual void onTabCloseButtonClicked(Tab *) override;
        virtual void onHovered(Item *, bool, void *) override;
        virtual void onClicked(Item*, IItemEventHandler::EMouseButton) override;
        virtual void onCurrentIndexChanged(DropDownBoard* pDropDownBoard, int index , Item* pItem) override;
        virtual bool onDragOff(Tab *) override;
        virtual bool onDoesAcceptDrop(DragMove *) const override;
        virtual void onDrop(DragMove *) override;
        virtual bool onReplayJournal(const ArrangementAreaContent::JournalParameters &) override;
        virtual void onClicked(Item *) override;
        // Inherits from INotificationCenterEventHandler...
        virtual void onEvent(INotificationCenterEventArgs *) override;
    private:
        void handleEvent(DisplayManagerEventArgs *);
        void handleEvent(ProjectDisplayEventArgs *);
        void handleEvent(AssetDisplayEventArgs *);
        void handleDrop(DragMove *);
        void handleActivity(bool, TabBar *);
        void handleScenario(bool, const Scenario *, TabBar *);
        const TabBar * tabBar() const;
              TabBar * tabBar();
        void notifyToActivateCurrentTab(TabBar *);
        void notifyToCloseTab(const Tab *);

        void takeBackIsolatedArrangementAreas();

        void  eraseTabs(TabBar *, IProjectDisplay *) const;
        void appendTabs(TabBar *, IProjectDisplay *) const;

        void setDisplayUnitActive(bool);

    private:
        gcmp::OwnerPtr< Info > m_iconButton, m_closeButton;
        gcmp::WeakPtr< IProjectDisplay > m_handlingEvent;
        gcmp::OwnerPtr< DropDownBoard > m_dropDownBoard;
    };
}
